package com.tang.thepath;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.tang.thepath.model.RequestModel;
import com.tang.thepath.service.BizService;
import com.tang.thepath.service.HttpSubscriber;

public class ProblemActivity extends BaseActivity {

    private EditText editTitle;
    private EditText editContent;
    private Button btnSave;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_problem);

        editTitle = (EditText) findViewById(R.id.edit_title);
        editContent = (EditText) findViewById(R.id.edit_content);
        btnSave = (Button) findViewById(R.id.btn_save);

        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String title = editTitle.getText().toString();
                String content = editContent.getText().toString();

                if(title.isEmpty()){
                    toast("标题不能为空");
                    return;
                }

                if(content.isEmpty()){
                    toast("内容不能为空");
                    return;
                }

                RequestModel.SaveProblemRequest request = new RequestModel.SaveProblemRequest();
                request.title = title;
                request.content = content;
                showLoading("数据提交中");
                BizService.saveProblem(request).subscribe(new HttpSubscriber<RequestModel.IdResponse>() {
                    @Override
                    protected void onSuccess(RequestModel.IdResponse idResponse) {
                        String message = "存储成功:"+idResponse.id;
                        Log.i(getTag(),message);
                        toast(message);
                        dismisLoading();
                        finish();
                    }
                });
            }
        });

    }
}
